﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

using MaxStudio.Concrete.DBUtility;

namespace MaxStudio.Concrete.Server.Dao
{
    public partial class ConcreteDaoDataContext : System.Data.Linq.DataContext
    {
        #region RPTAshReview

        public List<tb_RPT_AshReview> GetAllAshReview()
        {

            var query = (from obj in this.tb_RPT_AshReviews
                         where obj.IsDelete == 0
                         select obj).ToList();
            return query;
        }


        public List<tb_RPT_AshReview> GetAshReviewByContition(string strSequence, string strProjectName, string strASHManufacturer
                                                                        , string strOutSequence, string strInDate, string strTestDate)
        {
            var tq = from obj in this.tb_RPT_AshReviews
                     where obj.IsDelete == 0
                     select obj;

            if (strSequence.Length > 0)
            {
                tq = tq.Where(entity => entity.Sequence == strSequence);
            }

            if (strProjectName.Length > 0)
            {
                tq = tq.Where(entity => entity.ProjectName == strProjectName);
            }
            if (strASHManufacturer.Length > 0)
            {
                tq = tq.Where(entity => entity.ASHManufacturer == strASHManufacturer);
            }
            if (strOutSequence.Length > 0)
            {
                tq = tq.Where(entity => entity.OutSequence == strOutSequence);
            }
            if (strInDate.Length > 0)
            {
                tq = tq.Where(entity => entity.InDate == strInDate);
            }
            if (strTestDate.Length > 0)
            {
                tq = tq.Where(entity => entity.TestDate == strTestDate);
            }
            var query = tq.ToList();
            return query;
        }

        public List<tb_RPT_AshReview> GetAshReviewByProjectName(string strProjectName)
        {

            var query = (from obj in this.tb_RPT_AshReviews
                         where obj.IsDelete == 0 && obj.ProjectName == strProjectName
                         select obj).ToList();
            return query;
        }

        public tb_RPT_AshReview GetAshReviewById(int id)
        {
            return this.tb_RPT_AshReviews.SingleOrDefault(tb_RPT_AshReviews => tb_RPT_AshReviews.Id == id);
        }

        public void CreateAshReview(tb_RPT_AshReview entity)
        {
            entity.CreateDate = DateTime.Now;
            entity.CreateBy = 1;
            entity.ModifyDate = DateTime.Now;
            entity.ModifyBy = 1;
            tb_RPT_AshReviews.InsertOnSubmit(entity);
            this.SubmitChanges();

        }

        public void ModifyAshReview(tb_RPT_AshReview entity)
        {
            tb_RPT_AshReview instance = this.tb_RPT_AshReviews.SingleOrDefault(p => p.Id == entity.Id);
            instance.Sequence = entity.Sequence;
            instance.ProjectName = entity.ProjectName;
            instance.ASHManufacturer = entity.ASHManufacturer;
            instance.OutSequence = entity.OutSequence;
            instance.InDate = entity.InDate;
            instance.TestDate = entity.TestDate;
            instance.STANFineness = entity.STANFineness;
            instance.STANWaterDemandRatio = entity.STANWaterDemandRatio;
            instance.STANIgnitionLoss = entity.STANIgnitionLoss;
            instance.STANMoistureContent = entity.STANMoistureContent;
            instance.STANSulfurTrioxide = entity.STANSulfurTrioxide;
            instance.MEASUFineness = entity.MEASUFineness;
            instance.MEASUWaterDemandRatio = entity.MEASUWaterDemandRatio;
            instance.MEASUIgnitionLoss = entity.MEASUIgnitionLoss;
            instance.MEASUMoistureContent = entity.MEASUMoistureContent;
            instance.MEASUSulfurTrioxide = entity.MEASUSulfurTrioxide;
            instance.TestStandard = entity.TestStandard;
            instance.TestResult = entity.TestResult;
            instance.Remark = entity.Remark;
            instance.Review = entity.Review;
            instance.Approval = entity.Approval ;
            instance.Test = entity.Test; 

            instance.IsDelete = entity.IsDelete;
            instance.ModifyBy = 1; //Need to get current user
            instance.ModifyDate = DateTime.Now;

            this.SubmitChanges();
        }

        public void DeleteAshReview(tb_RPT_AshReview entity)
        {
            tb_RPT_AshReview deleteEntity = tb_RPT_AshReviews.SingleOrDefault(p => p.Id == entity.Id);
            tb_RPT_AshReviews.DeleteOnSubmit(deleteEntity);

            this.SubmitChanges();
        }

        #endregion

    }

}
